home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / ads / sample / calusrf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  3.0 KB  |  100 lines

  1. /* Next available MSG number is     3 */
  2.  
  3. /*****************************************************************************
  4.       CALUSRF.C
  5.       (C) Copyright 1988-1994 by Autodesk, Inc.
  6.  
  7.       This program is copyrighted by Autodesk, Inc. and is  licensed
  8.       to you under the following conditions.  You may not distribute
  9.       or  publish the source code of this program in any form.   You
  10.       may  incorporate this code in object form in derivative  works
  11.       provided  such  derivative  works  are  (i.) are  designed and 
  12.       intended  to  work  solely  with  Autodesk, Inc. products, and 
  13.       (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright  
  14.       1988-1993 by Autodesk, Inc."
  15.  
  16.       AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  17.       AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  18.       CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  19.       DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  20.       UNINTERRUPTED OR ERROR FREE.
  21.  
  22.   Description: The user-defined functions for the Geometry Calculator.
  23.  
  24. *****************************************************************************/
  25.  
  26.  
  27. /****************************************************************************/
  28. /*  INCLUDES                                                                */
  29. /****************************************************************************/
  30.  
  31. #define MODULE_ID CALUSRF_C_
  32.  
  33. #include "cal.h"
  34.  
  35. #include "xmf.h"
  36. #include "ads_ix.h"
  37.  
  38.  
  39. /****************************************************************************/
  40. /*.doc cal_MAX_func(internal)*/
  41. /*+
  42.   Calculator function which returns maximum from a given set of numbers.
  43. -*/
  44. /****************************************************************************/
  45.  
  46.  
  47. static void
  48. /*FCN*/cal_MAX_func()
  49. {
  50.     int        i;
  51.     double     max;
  52.     value_type type;
  53.  
  54.     if (no_of_params < 2) {
  55.         error(0, XMSG("Function 'MAX' reguires at least two parameters", 1));
  56.         return;
  57.     }
  58.  
  59.     max  = -1e30;
  60.     type = int_type;
  61.  
  62.     for (i=0; i<no_of_params; i++) {
  63.         if (!IS_REAL(i)) {
  64.             error(0, XMSG("Function 'MAX' requires only real or int parameters", 2));
  65.             return;
  66.         }
  67.         if (params[i].type == real_type) {
  68.             type = real_type;
  69.         }
  70.         if (params[i].r > max) {
  71.             max = params[i].r;
  72.         }
  73.     } /*for*/
  74.  
  75.     result.type = type;
  76.     result.r    = max;
  77.  
  78. } /*cal_MAX_func*/
  79.  
  80.  
  81. /****************************************************************************/
  82. /*.doc cal_register_user_functions(external)*/
  83. /*+
  84.   Insert the registration of all your calculator functions into the       
  85.   following function. The example how to do is, we hope, selfexplanatory. 
  86. -*/
  87. /****************************************************************************/
  88.  
  89.  
  90. void
  91. /*FCN*/cal_register_user_functions()
  92. {
  93.     cal_register_function(/*MSG0*/"MAX", cal_MAX_func);
  94.  
  95.     /* Add registering your own functions here.... */
  96.  
  97. } /*cal_register_user_functions*/
  98.  
  99.  
  100.